﻿using BellAssistant.DSS;
using BellAssistant.Model.Tables;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BellAssistant.DataManager
{
    public partial class GoodsCategoryManage : FrmBase
    {
        public GoodsCategoryManage()
        {
            InitializeComponent();
            btnAdd.Click += btnAdd_Click;
            btnSearch.Click += btnSearch_Click;
            this.Load += GoodsCategoryManage_Load;
            gridView1.OptionsBehavior.Editable = false;
            gridControl1.DoubleClick += GridControl1_DoubleClick;
        }

        private void GridControl1_DoubleClick(object sender, EventArgs e)
        {
        
           // txtCategoryName.Text = data["CategoryName"].ToString();
        }

        private void GoodsCategoryManage_Load(object sender, EventArgs e)
        {
            txtNewName.ReadOnly = true;
            btnSearch_Click(sender, e);
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            List<ProductCategory> list = CreateDataSourceService.IDataSourceService.GetAllProductCategory();
            gridControl1.DataSource = list;
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            ProductCategory product = new ProductCategory();
            if (string.IsNullOrEmpty(txtCategoryName.Text))
            {
                MessageBox.Show("商品类别不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            product.CategoryName = txtCategoryName.Text;
            bool saveFlg = CreateDataSourceService.IDataSourceService.SaveCategory(product, "");
            if (saveFlg)
            {
                MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                btnSearch_Click(sender, e);
            }
            else
            {
                MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

        }


    }
}
